package test_achieve.courierapp;

import constant.Constant;
import cucumber.api.java.en.Given;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import util.tools.CommonTools;

import java.util.List;

/**
 * Created by chenkuo on 2017/12/21.
 */
public class OrderUI {

    @Given("^抢单界面，确认订单信息：(.*)：(.*)：(.*)：(.*)：(.*)：(.*)$")
    public void 抢单界面确认订单信息(String distance,String wight,String remark,String sendAdress,String pickUpAdress,String goods) throws Throwable {
        String dis = Constant.driverCourier.findElement(By.id("distance_txt")).getText();//里程，重量，距离当前位置信息
        CommonTools.assertStringContain(dis,distance);
        CommonTools.assertStringContain(dis,wight);
        String tvRemarks = Constant.driverCourier.findElement(By.id("tvRemarks")).getText();//订单备注
        CommonTools.assertStringContain(tvRemarks,remark);
        String from_addr_txt = Constant.driverCourier.findElement(By.id("from_addr_txt")).getText();//寄件地址
        CommonTools.assertStringContain(from_addr_txt,sendAdress);
        String addr_txt = Constant.driverCourier.findElement(By.id("addr_txt")).getText();//收件地址
        CommonTools.assertStringContain(addr_txt,pickUpAdress);
        String goodsname_txt = Constant.driverCourier.findElement(By.id("goodsname_txt")).getText();//物品名称
        CommonTools.assertStringContain(goodsname_txt,goods);

    }

    @Given("^订单详情界面，确认订单信息：(.*)：(.*)：(.*)：(.*)：(.*)$")
    public void 订单详情界面确认订单信息(String distance,String wight,String remark,String sendAdress,String pickUpAdress) throws Throwable {
        String dis = Constant.driverCourier.findElement(By.id("tv_orderPrice")).getText();//里程，重量，距离当前位置信息
        CommonTools.assertStringContain(dis,distance);
        CommonTools.assertStringContain(dis,wight);
        String tvRemarks = Constant.driverCourier.findElement(By.id("tv_remarks")).getText();//订单备注
        CommonTools.assertStringContain(tvRemarks,remark);
        String from_addr_txt = Constant.driverCourier.findElement(By.id("from_addr_txt")).getText();//寄件地址
        CommonTools.assertStringContain(from_addr_txt,sendAdress);
        String addr_txt = Constant.driverCourier.findElement(By.id("to_addr_txt")).getText();//收件地址
        CommonTools.assertStringContain(addr_txt,pickUpAdress);
    }

    @Given("^就位详情页面，确认订单信息：(.*)：(.*)：(.*)：(.*)$")
    public void 就位详情页面确认订单信息(String sendAdress,String room,String remark,String goods) throws Throwable {
        String from_addr_txt = Constant.driverCourier.findElement(By.id("from_addr_txt")).getText();//寄件地址
        CommonTools.assertStringContain(from_addr_txt,sendAdress);
        String from_addr_detail = Constant.driverCourier.findElement(By.id("from_addr_detail")).getText();//寄件房间号
        CommonTools.assertStringContain(from_addr_detail,room);
        String beizhu_txt = Constant.driverCourier.findElement(By.id("beizhu_txt")).getText();//订单备注
        CommonTools.assertStringContain(beizhu_txt,remark);
        String goods_name = Constant.driverCourier.findElement(By.id("goods_name")).getText();//物品名称
        CommonTools.assertStringContain(goods_name,goods);

    }

    @Given("^收件详情页面，确认订单信息：(.*)：(.*)：(.*)：(.*)$")
    public void 收件详情页面确认订单信息(String pickUpAdress,String room,String remark,String goods) throws Throwable {
//：<收地址>：<收房间号>：<备注>：<物品>
        String to_addr_txt = Constant.driverCourier.findElement(By.id("to_addr_txt")).getText();//收件地址
        CommonTools.assertStringContain(to_addr_txt,pickUpAdress);
        String to_addr_detail = Constant.driverCourier.findElement(By.id("to_addr_detail")).getText();//收件房间号
        CommonTools.assertStringContain(to_addr_detail,room);
        String beizhu_txt = Constant.driverCourier.findElement(By.id("beizhu_txt")).getText();//订单备注
        CommonTools.assertStringContain(beizhu_txt,remark);
        String goods_name = Constant.driverCourier.findElement(By.id("goods_name")).getText();//物品名称
        CommonTools.assertStringContain(goods_name,goods);
    }

    @Given("^今日订单中，确认订单信息：(.*)：(.*)：(.*)：(.*)：(.*)$")
    public void 今日订单中确认订单信息(String distance,String wight,String sendAdress,String pickUpAdress,String type) throws Throwable {
        List<WebElement> price_head = Constant.driverCourier.findElements(By.id("price_head"));
        CommonTools.assertStringContain(price_head.get(0).getText(),distance);
        CommonTools.assertStringContain(price_head.get(0).getText(),wight);
        List<WebElement> from_addr_txt = Constant.driverCourier.findElements(By.id("from_addr_txt"));
        CommonTools.assertStringContain(from_addr_txt.get(0).getText(),sendAdress);
        List<WebElement> addr_txt = Constant.driverCourier.findElements(By.id("addr_txt"));
        CommonTools.assertStringContain(addr_txt.get(0).getText(),pickUpAdress);
        List<WebElement> item_order_type = Constant.driverCourier.findElements(By.id("item_order_type"));
        CommonTools.assertStringContain(item_order_type.get(0).getText(),type);
    }

}
